home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / strings / rngecont.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  1.4 KB  |  54 lines

  1. ;unsigned short  range_count(strg,char_1,char_2);
  2. ;  unsigned char  *strg,char_1,char_2;
  3.  
  4.     EXTRN  _memory_model:byte
  5.  
  6. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  7.     ASSUME CS:_TEXT
  8.     PUBLIC _range_count
  9. _range_count proc near
  10.     push bp            ;
  11.     mov  bp,sp        ;set up stack frame
  12.     push si            ;
  13.     push ds            ;
  14.     cmp  _memory_model,0    ;near or far?
  15.     jle  begin        ;jump if near
  16.     inc  bp            ;else add 2 to BP
  17.     inc  bp            ;
  18. begin:    cmp  _memory_model,2    ;data near or far?
  19.     jb   L0            ;jump if near
  20.     lds  si,dword ptr[bp+4]  ;DS:SI pts to Strg
  21.     inc  bp            ;add 2 to BP since dword ptr
  22.     inc  bp            ;
  23.     jmp  short L00        ;
  24. L0:    mov  si,[bp+4]        ;near case
  25. L00:    sub  dx,dx        ;clear DX for tally
  26.     mov  ah,[bp+6]        ;get one end of range
  27.     mov  al,[bp+8]        ;get other end of range
  28.     cmp  ah,al        ;compare the values
  29.     jae  L1            ;jump if AH >= AL
  30.     xchg ah,al        ;else, high value to AH
  31. L1:    cmp  byte ptr[si],0    ;test for null string
  32.     je   L4            ;quit if null
  33. L2:    mov  bl,[si]        ;get character
  34.     inc  si            ;forward ptr for next time
  35.     cmp  bl,0        ;end of string?
  36.     je   L4            ;
  37.     cmp  bl,ah        ;test against high char
  38.     ja   L3            ;skip ahead if above
  39.     cmp  bl,al        ;test against low char
  40.     jb   L3            ;skip ahead if below
  41.     inc  dx            ;increment counter
  42. L3:    jmp  short L2        ;go test next char
  43. L4:    mov  ax,dx        ;set value for return
  44.     pop  ds            ;
  45.     pop  si            ;
  46.     pop  bp            ;
  47.     cmp  _memory_model,0    ;quit
  48.     jle  quit        ;
  49.     db   0CBh        ;RET far
  50. quit:    ret            ;RET near
  51. _range_count ENDP
  52. _TEXT    ENDS
  53.     END
  54.